<?php
    
    # Classes de Modelo e PHPMailer

    require_once( CLASS_EMAIL ); 
    require_once( "tools/class/SessionController.class.php" );   
    require_once( CLASS_FUNCTIONS );
    require_once( CLASS_MENSAGEM ); 
    
    require_once( "control/AutenticarController.class.php" );
    

    class IndexController extends MainController {
       
        private $usuarioPK;
        private $usuarioName;
        private $usuarioPas;
        private $usuarioMail;
         
        public function __construct(){
            parent::__construct();
            
            //# endere?o IP do Servidor
            $server = $_SERVER['SERVER_ADDR'];

            if($server == "127.0.0.1"):
                $this->root = "http://localhost/ericluciano-trix/Application";
                $this->url = "http://localhost/ericluciano-trix";
            else:
                $this->root = "http://www.trixcomunicacaocriativa.com.br/projeto_site/Application";
                $this->url = "http://www.trixcomunicacaocriativa.com.br/projeto_site";
            endif;
            
            $base_root = $this->root;
            $base_js = $this->root."/js";
            $base_css = $this->root."/css";
            $base_image = $this->root."/images";
            $base_uploaded = $this->url."/uploaded";
            $base_plugins = $this->root."/plugins";
            

            # Todas as P?ginas
            parent::setAttribute("base_root",$base_root);
            parent::setAttribute("base_js",$base_js);
            parent::setAttribute("base_css",$base_css);
            parent::setAttribute("base_image",$base_image);
            parent::setAttribute("base_uploaded",$base_uploaded);
            parent::setAttribute("base_plugins",$base_plugins);
            
            
            
            $this->funcoes = new FuncoesFacade();            
            # Autentica??o do Usuario Nome e Email
            $this->session = new SessionController();
            
            $usuario_session_pk = $this->session->resgata_session("trix_auth_pk");
            $usuario_session_email = $this->session->resgata_session("trix_auth_email");
            $usuario_checkpoint = $this->session->resgata_session("trix_check");
            
            #checkpoint
            $checkpoint = md5("trix_hotsite".$usuario_session_email);
            

if( ($checkpoint == $usuario_checkpoint) && (isset($usuario_session_pk)) && ( $usuario_session_pk != 0) ):
  parent::setAttribute("trix_usuario_id",$this->session->resgata_session("trix_auth_pk"));               parent::setAttribute("trix_usuario_nome",$this->session->resgata_session("trix_auth_name"));
  parent::setAttribute("trix_usuario_email",$this->session->resgata_session("trix_auth_email"));
  parent::setAttribute("check_alerta_login",2);
else:
  parent::setAttribute("trix_usuario_id",0);
  parent::setAttribute("check_alerta_login",0);
        
endif;

            
            
            
}
        
        public function defaultAction(){
            
            if(!$this->funcoes->check_point_usuario()){
                $this->login_site();
                exit;
            }else{
                header("location: ".$this->root."/Cliente/Listar");
            }
            
            parent::setAttribute("lateral","main_lateral.html");
            parent::setAttribute("view","main_home.html");
            parent::execute("main_index.html");
        }
        
        public function Restrito(){
                      
            
            parent::setAttribute("lateral","main_lateral.html");
            parent::setAttribute("view","main_home.html");
            parent::execute("main_index.html");
            header("location: ".$this->root."/Cliente");
            
            
        }
        
        public function login_site(){
            parent::execute("main_login.html");
        }
        
        public function url_base(){
            $base = $this->root."/";
            return $base;
        }
        
        public function url_site(){
            return $this->url;
        }
        
        public function Logout(){
        $this->session->remove_session("trix_auth_pk");
        $this->session->remove_session("trix_auth_name");
        $this->session->remove_session("trix_auth_email");
        $this->session->remove_session("trix_check");
        $this->session->remove_session("erros_login");
        $this->session->remove_session("liberar_tentativa");            
        $this->session->destroySession();
        header("location: ".$this->root);
        }
        
        
        
        
        
        
         

}
?>
